package com.crl.rcdp.common.controller;

import com.cars.util.global.GlobalReturnCode;
import com.cars.util.json.JsonResult;
import com.cars.util.json.JsonResultUtil;
import com.crl.rcdp.common.service.CommonComboService;
import com.crl.rcdp.sys.dto.SysApiDTO;
import com.crl.rcdp.sys.service.SysApiService;
import com.crl.rcdp.sys.service.SysRoleService;
import com.crl.rcdp.sys.vo.SysRoleSearchVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 字典类公共接口
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020/6/22 17:44
 */
@RestController
@RequestMapping("/common")
public class CommonComboController {
    @Autowired
    private SysRoleService sysRoleService;
    @Autowired
    private CommonComboService commonComboService;
    @Autowired
    private SysApiService sysApiService;

    /**
     * 获取所有角色信息
     */
    @PostMapping("/combo/listSysRole")
    @ApiOperation(value = "角色列表下拉框")
    public JsonResult listSysRole(@RequestBody SysRoleSearchVO sysRoleSearchVO) {
        return JsonResultUtil.ok(sysRoleService.listSysRoleCombo());
    }

    @PostMapping("/combo/listGenAuthor")
    @ApiOperation(value = "代码生成器中用户列表")
    public JsonResult listGenAuthor() {
        return JsonResultUtil.ok(commonComboService.listGenAuthor());
    }

    @GetMapping("/combo/listGenTable")
    @ApiOperation(value = "代码生成器中数据表列表")
    public JsonResult listGenTable(@RequestParam("authorId") Integer authorId) {
        if (authorId == null) {
            return JsonResultUtil.error(GlobalReturnCode.PARAMS_ERROR);
        } else {
            return JsonResultUtil.ok(commonComboService.listGenTable(authorId));
        }
    }


    @PostMapping("/combo/listApitype")
    @ApiOperation(value = "接口类型")
    public JsonResult listApitype() {
        return JsonResultUtil.ok(commonComboService.listApitype());
    }


    /**
     * 获取资源树
     */
    @PostMapping("/combo/getSysApiTree")
    @ApiOperation(value = "获取接口树")
    public JsonResult getSysApiTree(@RequestBody SysApiDTO sysApiDTO) {
        return JsonResultUtil.ok(sysApiService.getSysApiTree());
    }
}
